<template>
  <div class="container">
    <div class="title"><span> 太湖度假区水司管网地理信息系统</span></div>
    <div class="login">
      <div class="loginTitle">用户登录</div>
      <div class="loginItem">
        <input type="text" v-model="user.username" placeholder="请输入用户名" />
        <i class="userIcon"></i>
      </div>
      <div class="loginItem">
        <input
          :type="isShowPassword ? 'text' : 'password'"
          v-model="user.password"
          placeholder="请输入密码"
        />
        <i class="passwordIcon"></i>
        <img
          class="eyeIcon"
          @click="isShowPassword = !isShowPassword"
          :src="
            isShowPassword
              ? require('../../assets/密码显示.png')
              : require('../../assets/密码隐藏.png')
          "
          alt=""
        />
        <!-- <img
          @click="isShowPassword = !isShowPassword"
          :src="
            isShowPassword
              ? require('../../assets/显示密码.png')
              : require('../../assets/不显示密码.png')
          "
          alt=""
        /> -->
      </div>
      <div class="rememberPassword">
        <input
          type="checkbox"
          name="remember"
          v-model="isRemember"
          @input="setStorePassword"
        />
        <label for="remember">记住密码</label>
      </div>
      <!-- <div class="loginCode"><span>验证码：</span><input type="text" /></div> -->
      <div class="loginBtn"><button @click="login">登录</button></div>
    </div>
  </div>
</template>

<script>
import userIcon from "../../assets/svg/224用户.svg";
import passwordIcon from "../../assets/svg/密码.svg";
import { loginSure, getUserInfo } from "@/api/login";
export default {
  name: "loginPanel",
  data() {
    return {
      isRemember: false,
      isShowPassword: false,
      user: {
        username: "",
        password: "",
      },
    };
  },
  mounted() {
    let userPassword = localStorage.getItem("storeUserPassword");
    if (userPassword) {
      this.isRemember = true;
      this.user = JSON.parse(userPassword);
    }
  },
  methods: {
    setStorePassword(event) {
      console.log(event.target.checked);
      if (event.target.checked) {
        localStorage.setItem("storeUserPassword", JSON.stringify(this.user));
      } else {
        localStorage.removeItem("storeUserPassword");
      }
    },
    login() {
      loginSure(this.user).then(async (res) => {
        if (!res) {
          this.$message.error("登录失败");
          return;
        }
        if (res.code == 200) {
          localStorage.setItem("token", res.message);
          await getUserInfo({
            username: this.user.username,
          }).then((res) => {
            console.log(res, "用户信息获取");
            this.$message.success("登录成功");
            this.$router.push({ path: "/homePage" });
            localStorage.setItem("userInfo", JSON.stringify(res.data));
          });
        } else {
          this.$message.error(res.message);
        }
      });
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/assets/css/px2vwvh.scss";
.container {
  width: 100%;
  height: 100%;
  background-image: url("../../assets/bg.png");
  background-size: cover;
  background-repeat: no-repeat;
  .title {
    position: absolute;
    left: 50%;
    // top: 14rem;
    @include px2vh(top, 218);
    transform: translateX(-50%);
    span {
      font-family: YouSheBiaoTiHei;
      @include px2font(58);
      font-weight: normal;
      text-align: center;
      @include px2vw(letter-spacing, 10);
      font-variation-settings: "opsz" auto;
      background: linear-gradient(90deg, #0a51a9 -41%, #2ea1ff 76%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
      background-clip: text;
    }
  }
  .login {
    @include px2margin(47, 0, 0, 0);
    @include px2vw(width, 671);
    @include px2vh(height, 464);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    overflow: hidden;
    background-size: 100% 100%;
    background-image: url("../../assets/底部.png");
    .loginTitle {
      font-family: 思源黑体;
      @include px2font(30);
      font-weight: normal;
      // @include px2vh(height, 30);
      @include px2vh(margin-bottom, 36);
      text-align: center;
      @include px2vh(margin-top, 38);
      @include px2vw(letter-spacing, 10);
      color: rgba(0, 161, 255, 0.9);
    }
    .loginCode {
      font-size: 1.5rem;
      font-weight: 300;
      margin: 1rem 0;
      display: flex;
      position: relative;
      input {
        width: 20%;
        height: 1.5rem;
        border-radius: 5px;
        border: 1px solid #ccc;
        outline: none;
      }
    }
    .loginItem {
      @include px2font(16);
      font-weight: 300;
      @include px2margin(0, 0, 27, 0);
      display: flex;
      position: relative;
      justify-content: center;
      .userIcon {
        position: absolute;
        top: 50%;
        left: 12%;
        @include px2vw(width, 24);
        @include px2vh(height, 24);
        background-image: url("@/assets/svg/224用户.svg");
        background-size: contain;
        background-repeat: no-repeat;
        transform: translateY(-50%);
        pointer-events: none;
      }
      .passwordIcon {
        position: absolute;
        top: 50%;
        left: 12%;
        @include px2vw(width, 24);
        @include px2vh(height, 24);
        background-image: url("@/assets/svg/密码.svg");
        background-size: contain;
        background-repeat: no-repeat;
        transform: translateY(-50%);
        pointer-events: none;
      }
      .eyeIcon {
        cursor: pointer;
        position: absolute;
        top: 50%;
        right: 12%;
        @include px2vw(width, 24);
        @include px2vh(height, 24);

        transform: translateY(-50%);
      }
      span {
        width: 20%;
      }
      input {
        @include px2padding(0, 0, 0, 55);
        box-sizing: border-box;
        @include px2vw(width, 550);
        @include px2vw(height, 60);
        opacity: 1;
        background: rgba(6, 135, 205, 0.3);
        box-sizing: border-box;
        @include px2border(3, solid, rgba(11, 161, 248, 0.4));
        outline: none;
        font-family: 思源黑体;
        @include px2font(16);
        font-weight: normal;
        letter-spacing: 0px;
        color: rgba(255, 255, 255, 0.5);
      }
      input::placeholder {
        color: rgba(255, 255, 255, 0.5);
      }
    }
    .loginBtn {
      display: flex;
      justify-content: center;
      button {
        background: #0391e3;
        @include px2vh(height, 60);
        @include px2vw(width, 550);
        color: #fff;
        font-family: Source Han Sans;
        @include px2font(18);
        font-weight: bold;
        text-align: center;
        letter-spacing: 0px;
        font-variation-settings: "opsz" auto;
        color: #ffffff;
        border: 0;
        cursor: pointer;
      }
    }
    .rememberPassword {
      display: flex;
      align-items: center;
      @include px2margin(0, 0, 28, 0);
      @include px2vw(margin-left, 61);
      input[type="checkbox"] {
        position: relative;
        visibility: hidden;
        @include px2vw(width, 22);
        @include px2vh(height, 22);
        @include px2border(3, solid, rgba(11, 161, 248, 0.4));
        @include px2margin(0, 9, 0, 0);
      }
      input[type="checkbox"]:after {
        cursor: pointer;
        position: absolute;
        top: 0;
        @include px2vw(width, 22);
        @include px2vh(height, 22);
        content: " ";
        background: rgba(6, 135, 205, 0.3);
        visibility: visible;
        @include px2border(3, solid, rgba(11, 161, 248, 0.4));
      }

      input[type="checkbox"]:checked:after {
        content: "✔";
        position: absolute;
        @include px2font(15);
        left: 0;
        top: 0;
        background: rgba(6, 135, 205, 0.3);
        font-family: Source Han Sans CN, Source Han Sans CN;
        color: #ffffff;
        text-align: center;
      }
      label {
        font-family: 思源黑体;
        @include px2font(16);

        font-weight: normal;

        letter-spacing: 0px;
        color: rgba(0, 161, 255, 0.9);
      }
    }
  }
}
</style>
